package example.documentbased.mainModule.models.mappers
{
	import example.documentbased.mainModule.models.doman.Editor;
	import example.documentbased.mainModule.models.factories.ItemsFactory;
	import example.documentbased.mainModule.models.vo.EditorVO;
	
	import mx.collections.ArrayList;

	public class EditorMapper
	{
		private var _factory:ItemsFactory;
		
		public function EditorMapper(factory:ItemsFactory)
		{
			_factory = factory;
		}
		
		public function fromDomain(value:Editor):EditorVO
		{
			return _factory.createEditorVO(value.id, value.name, value.color, new ArrayList());
		}
		
		public function fromDomainItems(items:Object):Array
		{
			const result:Array = [];
			for each (var item:Editor in items) 
			{
				result.push(fromDomain(item));
			}
			return result;
		}
		
		public function toDomain(value:EditorVO):Editor
		{
			return _factory.createEditor(value.id, value.name, value.color);
		}
		
		public function toDomainItems(items:Object):Array
		{
			const result:Array = []; 
			for each (var item:EditorVO in items) 
			{
				result.push(toDomain(item));
			}
			return result;
		}
	}
}